package cn.wolfcode.web.controller;


import cn.wolfcode.domain.ConsumptionItem;
import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IConsumptionItemService;
import cn.wolfcode.utils.RequestPermission;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/consumptionItem")
public class ConsumptionItemController {
    @Autowired
    private IConsumptionItemService consumptionItemService;
   

    @RequestMapping("/list")
    @RequestPermission(name="明细单查询",expression = "consumptionItem:list")
    public String list(Model model , @ModelAttribute("qo") QueryObject qo){
        PageInfo<ConsumptionItem> pageInfo = consumptionItemService.query(qo);
        model.addAttribute("pageInfo",pageInfo);



        return "consumptionItem/list" ;
    }



    @RequestMapping("/input")
    public String input(Long id,Model model){
        if (id != null) {
            model.addAttribute("consumptionItem",consumptionItemService.selectById(id));
        }
        return "/consumption/input" ;
    }

    @RequestMapping("/save")
    @ResponseBody
    @RequestPermission(name="明细单编辑",expression = "consumptionItem:save")
    public JsonResult save(ConsumptionItem item){
        if (item.getId() != null){
            consumptionItemService.update(item);
        }else {
            consumptionItemService.insert(item);
        }

        return new JsonResult(true, "操作成功");
    }
}
